<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class MY_Model extends Model {
	var $tname = "";
	
	function MY_Model($tn = "") {
		$this->tname = $tn;
		parent::Model ();
	}
	
	function get_one($id) {
		//echo $this->tname;
		$sql = "SELECT * FROM " . $this->tname . " WHERE id = ?";
		$query = $this->db->query ( $sql, array ($id ) );
		$data = $query->row_array ();
		return $data;
	}
	
	function get_all() {
		$sql = "SELECT * FROM " . $this->tname;
		$query = $this->db->query ( $sql );
		$data = $query->result ();
		return count ( $data ) == 0 ? false : $data;
	}
	
	function insert($data) {
		 return $this->db->insert ( $this->tname, $data );
	}
	
	function get_insert_id() {
		return $this->db->insert_id();
	}
	
	function update($id, $data) {
		$this->db->where ( 'id', $id );
		$this->db->update ( $this->tname, $data );
	}
	
	function delete($id) {
		$this->db->where ( 'id', $id );
		$this->db->delete($this->tname);
	}
	/**
	 * @return the $tname
	 */
	public function getTname() {
		return $this->tname;
	}

	/**
	 * @param $tname the $tname to set
	 */
	public function setTname($tname) {
		$this->tname = $tname;
	}

}